package m.jclecai.com.bean;

import com.alibaba.fastjson.JSONObject;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import m.jclecai.com.inter.IAdapterItem;


public class ZqItem implements IAdapterItem {

	private String[] codes;//
	private boolean dan_select; // 胆是否勾选
    //key 0-胜平负 1-让球胜平负 2-总进球 3-比分 4-半全场 5-胜分差 6- 7-
	Map<String,Map<String,String>> map;//勾选的信息
    private boolean showDetail;//显示详细赛事分析
	private JSONObject ratio;//赛事详情

	public ZqItem(String[] codes, boolean dan_select) {
		this.codes = codes;
		this.dan_select = dan_select;
	}

	public String[] getCodes() {
		return codes;
	}

	public void setCodes(String[] codes) {
		this.codes = codes;
	}

	public boolean isDan_select() {
		return dan_select;
	}

	public void setDan_select(boolean dan_select) {
		this.dan_select = dan_select;
		codes[0] = codes[0].replaceAll("@","");
		if(dan_select){
			codes[0] = "@"+codes[0];
		}
	}

	@Override
	public long getItemId() {
		return 0;
	}

	public Map<String, Map<String, String>> getMap() {
		return map;
	}

	public void setMap(Map<String, Map<String, String>> map) {
		this.map = map;
	}

	public int getMapLength(){
		int length=0;
		if(map != null){
            for(Map<String, String> mp :map.values()){
                length +=mp.values().size();
            }
		}
		return length;
	}

    //key 0-胜平负 1-让球胜平负 2-总进球 3-比分 4-半全场 5-胜分差 6- 7-
	public String format(String key){
        String value = "";
		if(map == null) return value;
        Map<String, String> strMap = map.get(key);
        if(strMap == null) return value;
        //勾选的数据 "0_spf_0_2.25_胜" -> "0_spf_0_2.25_胜"
        // 0-服务器数据下标，spf 类型 0-点击的下标用来排序 2.25倍数 胜显示的值
        String[] strs = strMap.keySet().toArray(new String[]{});
        int[] arrayKey = new int[strs.length];
        Map<Integer,String> nMap = new HashMap<>();
        //排序
        for (int j=0;j<strs.length;j++){
            String[] split = strs[j].split("_");
            arrayKey[j] = Integer.parseInt(split[2]);
            nMap.put(arrayKey[j],strs[j]);
        }
        Arrays.sort(arrayKey);
        //输出
        for (int j=0;j<arrayKey.length;j++){
            String keys = nMap.get(arrayKey[j]);
            String[] split = keys.split("_");
            value+=split[4]+" ";
        }
        return value;
	}

	public JSONObject getRatio() {
		return ratio;
	}

	public void setRatio(JSONObject ratio) {
		this.ratio = ratio;
	}

	public boolean isShowDetail() {
        return showDetail;
    }

    public void setShowDetail(boolean showDetail) {
        this.showDetail = showDetail;
    }
}
